package net.wesley.android.city;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import net.wesley.android.City;
import net.yebaihe.sdk.HttpConnection;

public class XiaMen extends City {

	private Handler request1handler=new Handler(){
		public void handleMessage(Message message){
			switch (message.what){
			case HttpConnection.DID_ERROR://DID ERROR
				callback.onComplete(-1, "");
				break;
			case HttpConnection.DID_SUCCEED://DID SUCC
				String body=(String)message.obj;
				int index=body.indexOf(">处理方式</td>");
				if (index>0){
					String[] rows = body.substring(index).split("<table")[0].split("<tr");
					String retvalue="";
					for (int i=1;i<rows.length-1;i++){
						String[] cols = rows[i].split("<td");
						String shijian=cols[2].split("</td")[0].split(">")[1].trim();
						String didian=cols[3].split("</td")[0].split(">")[1].trim();
						String code=cols[4].split("</a")[0].split(">")[2].trim();
						retvalue+=String.format("shijian:%s\ndidian:%s\ncode:%s\n\n",shijian,didian,code);
					}
					callback.onComplete(rows.length-2, retvalue);
				}
				else{
					Log.d("myown", body);
					callback.onComplete(-10001, "");
				}
				break;
			}
		}
	};

	public void requestParamsFinish(String[] values) {
		try {
			new HttpConnection(ctx,request1handler,"GBK").post("http://www.xmjj.gov.cn:8080/xmjj_cxfw/showClwfcxPagePo.action", 
					String.format("pagePo.hphm=%s&pagePo.hpzl=02&pagePo.clsbdh=%s&pagePo.sfzmhm=&pagePo.dabh=",
							URLEncoder.encode(chepai,"GBK"),values[0]));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean match(String chepai) {
		return chepai.startsWith("闽D");
	}

	@Override
	public String[] paramDesc() {
		String[] s={"车架号后6位"};
		return s;
	}

}
